<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      
    >
      <el-form-item label="薪酬组名称" prop="remunerationName">
        <el-input
          v-model="queryParams.remunerationName"
          placeholder="请输入薪酬组名称"
          :show-word-limit="true"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="薪酬组代码" prop="remunerationCode">
        <el-input
          v-model="queryParams.remunerationCode"
          placeholder="请输入薪酬组代码"
          :show-word-limit="true"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="描述" prop="describe">
        <el-input
          v-model="queryParams.describe"
          placeholder="请输入描述"
          :show-word-limit="true"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="修改人" prop="modifier">
        <el-input
          v-model="queryParams.modifier"
          placeholder="请输入修改人"
          :show-word-limit="true"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属雇主" prop="userId">
        <el-input
          v-model="queryParams.userId"
          placeholder="请输入所属雇主"
          :show-word-limit="true"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="算薪周期" prop="payCycle">
        <el-input
          v-model="queryParams.payCycle"
          placeholder="请输入算薪周期"
          :show-word-limit="true"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="计薪天数" prop="paidDays">
        <el-input
          v-model="queryParams.paidDays"
          placeholder="请输入计薪天数"
          :show-word-limit="true"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="支付方式" prop="modePayment">
        <el-input
          v-model="queryParams.modePayment"
          placeholder="请输入支付方式"
          :show-word-limit="true"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="支付币种" prop="currencyPayment">
        <el-input
          v-model="queryParams.currencyPayment"
          placeholder="请输入支付币种"
          :show-word-limit="true"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['remuneration:remuneration:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['remuneration:remuneration:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['remuneration:remuneration:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['remuneration:remuneration:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="remunerationList"
      @selection-change="handleSelectionChange"
      border
      :max-height="tableHeight"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column
        label="主键id"
        align="center"
        prop="id"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="薪酬组名称"
        align="center"
        prop="remunerationName"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="薪酬组代码"
        align="center"
        prop="remunerationCode"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="描述"
        align="center"
        prop="describe"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="修改人"
        align="center"
        prop="modifier"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="所属雇主"
        align="center"
        prop="userId"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="算薪周期"
        align="center"
        prop="payCycle"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="计薪天数"
        align="center"
        prop="paidDays"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="支付方式"
        align="center"
        prop="modePayment"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="支付币种"
        align="center"
        prop="currencyPayment"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['remuneration:remuneration:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['remuneration:remuneration:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
      :page-sizes="[10,20,30,50,100, 200]"
    />

    <!-- 添加或修改薪酬组对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="薪酬组名称" prop="remunerationName">
          <el-input
            v-model="form.remunerationName"
            placeholder="请输入薪酬组名称"
            :show-word-limit="true"
          />
        </el-form-item>
        <el-form-item label="薪酬组代码" prop="remunerationCode">
          <el-input
            v-model="form.remunerationCode"
            placeholder="请输入薪酬组代码"
            :show-word-limit="true"
          />
        </el-form-item>
        <el-form-item label="描述" prop="describe">
          <el-input
            v-model="form.describe"
            placeholder="请输入描述"
            :show-word-limit="true"
          />
        </el-form-item>
        <el-form-item label="修改人" prop="modifier">
          <el-input
            v-model="form.modifier"
            placeholder="请输入修改人"
            :show-word-limit="true"
          />
        </el-form-item>
        <el-form-item label="所属雇主" prop="userId">
          <el-input
            v-model="form.userId"
            placeholder="请输入所属雇主"
            :show-word-limit="true"
          />
        </el-form-item>
        <el-form-item label="算薪周期" prop="payCycle">
          <el-input
            v-model="form.payCycle"
            placeholder="请输入算薪周期"
            :show-word-limit="true"
          />
        </el-form-item>
        <el-form-item label="计薪天数" prop="paidDays">
          <el-input
            v-model="form.paidDays"
            placeholder="请输入计薪天数"
            :show-word-limit="true"
          />
        </el-form-item>
        <el-form-item label="支付方式" prop="modePayment">
          <el-input
            v-model="form.modePayment"
            placeholder="请输入支付方式"
            :show-word-limit="true"
          />
        </el-form-item>
        <el-form-item label="支付币种" prop="currencyPayment">
          <el-input
            v-model="form.currencyPayment"
            placeholder="请输入支付币种"
            :show-word-limit="true"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listRemuneration,
  getRemuneration,
  delRemuneration,
  addRemuneration,
  updateRemuneration,
} from "@/api/remuneration/remuneration";

export default {
  name: "Remuneration",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 薪酬组表格数据
      remunerationList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        remunerationName: null,
        remunerationCode: null,
        describe: null,
        modifier: null,
        userId: null,
        payCycle: null,
        paidDays: null,
        modePayment: null,
        currencyPayment: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询薪酬组列表 */
    getList() {
      this.loading = true;
      listRemuneration(this.queryParams).then((response) => {
        this.remunerationList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        remunerationName: null,
        remunerationCode: null,
        describe: null,
        updateTime: null,
        modifier: null,
        userId: null,
        payCycle: null,
        paidDays: null,
        modePayment: null,
        currencyPayment: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加薪酬组";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getRemuneration(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改薪酬组";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateRemuneration(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addRemuneration(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除薪酬组编号为"' + ids + '"的数据项？')
        .then(function () {
          return delRemuneration(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "remuneration/remuneration/export",
        {
          ...this.queryParams,
        },
        `remuneration_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
